import { Component, OnInit, Input } from '@angular/core';
import { AppGlobalService } from '../../shared/service/app-global.service';
import { HttpService } from 'src/app/shared/service/http.service';

@Component({
  selector: 'app-brand-list',
  templateUrl: './brand-list.component.html',
  styleUrls: ['./brand-list.component.scss'],
})
export class BrandListComponent implements OnInit {
  @Input() tagData: any;
  listdata: any ;
  params: any = {}; // 需要传的参数
    // 当前页数，默认1
  pageNo = 1;
  sessionId: any;
  constructor(private appGlobalService: AppGlobalService, private http: HttpService) { }

  ngOnInit() {
    console.log(this.tagData);
   /*  this.tagData=""; */
    this.listdata = this.tagData.data.data;
    console.log(this.listdata);
  }
    // 跳转到品牌详情
    go(obj) {
      console.log(obj);
      const pageParams = {
        pageId: obj.target,
        params: obj.params,
        sessionId: localStorage.getItem('sessionId')
    };
      console.log(pageParams);
      this.appGlobalService.goToForward(pageParams);
    }
    /* 上划获取翻页 */
    loadMoreData(event) {
      console.log(event);
      this.params = this.tagData.data.submit;
      // // 请求下一个页面
      this.pageNo = this.pageNo + 1;
      // // 参数
      this.params.content.pageNo = this.pageNo;
      this.params.sessionId = localStorage.getItem('sessionId');
      console.log(this.params);
      // 请求获取新数据
      this.http.post('application/submit', this.params, res => {
          console.log(res)
          console.log('cheng============================')
          // 请求数据成功
          if (res.success) {
              const resList = res.data.data;
              console.log(resList)
              // 追加返回数据
              if (resList && resList.length > 0) {
                  // 追加数据
                  resList.map(v => {
                    /*   v.payTimes = this.tranNumber(v.payTimes, 1); */
                      this.tagData.data.data.push(v);
                  });
              } else {
                  event.target.disabled = true;
                  // 没有数据了
                  // this.appGlobalService.showToast('没有数据了...', 1000, 'middle');
              }
          } else {
              // 请求失败，更新当前页数
              this.pageNo = this.pageNo - 1;
              // 请求数据失败
              this.appGlobalService.showToast(res.message, 2000, 'middle');
          }
          event.target.complete();
      }, err => {
          // 请求失败，更新当前页数
          this.pageNo = this.pageNo - 1;
          // 请求数据失败
          this.appGlobalService.showToast(err.message, 2000, 'middle');
          event.target.complete();

      });
  }
}
